#include <iostream>
#include <vector>
using namespace std;
// 86.03 %
class Solution
{
  public:
    bool canPlaceFlowers(vector<int> &flowerbed, int n)
    {
        if (flowerbed[0] == 0 && flowerbed[1] == 0)
        {
            flowerbed[0] = 1;
            n--;
        }
        for (int i = 1; i < flowerbed.size() - 1; i++)
        {
            if (flowerbed[i] == 0 && flowerbed[i - 1] == 0 && flowerbed[i + 1] == 0)
            {
                flowerbed[i] = 1;
                n--;
            }
        }
        if (flowerbed[flowerbed.size() - 1] == 0 && flowerbed[flowerbed.size() - 2] == 0)
        {
            flowerbed[flowerbed.size() - 1] = 1;
            n--;
        }
        if (n <= 0)
            return true;
        return false;
    }
};

int main()
{
    int arr[] = {1, 0, 0, 0, 1};
    int nn = 2;
    int n = sizeof(arr) / sizeof(arr[0]);
    vector<int> num(arr, arr + n);
    cout << Solution().canPlaceFlowers(num, nn);
    return 0;
}